#include "score.hpp"

Score::Score() {
	
}

Score::~Score() {
	
}

void Score::init(Engine *engine) {
	int i = 0;
	for(std::map<int, Player>::iterator iPlayer = engine->players.begin(); iPlayer != engine->players.end(); iPlayer++) {
		sf::String playerInfo;
		if((*iPlayer).second.score < 0) (*iPlayer).second.score = 0;
		playerInfo.SetPosition(sf::Vector2f(10.f, 10.f + 40.f * i));
		playerInfo.SetFont(engine->getFont("data/fonts/BELIEVER.TTF"));
		playerInfo.SetText((*iPlayer).second.name + " : " + val2str((*iPlayer).second.score) + " points");
		playerInfo.SetColor(sf::Color(255, 255, 255, 255));
		playerInfos[(*iPlayer).first] = playerInfo;
		i++;
	}
	
	scoreMusic.Open("data/music/Mellow_space.ogg");
	scoreMusic.Play();
}

void Score::cleanup() {
	scoreMusic.Stop();
}

void Score::pause() {
    scoreMusic.Pause();
}

void Score::resume() {
    scoreMusic.Play();
}

void Score::processEvent(Engine *engine, PlayerEvent& event) {
	switch(event.type) {
		case PlayerEvent::Action1:
		case PlayerEvent::Quit:
		{
			if(event.state)
				engine->popState();
			break;
		}
		default:
			break;
	}
}

void Score::update(Engine *engine) {
    
}

void Score::draw(Engine *engine) {
    for(std::map<int, sf::String>::iterator iPlayerInfo = playerInfos.begin(); iPlayerInfo != playerInfos.end(); iPlayerInfo++) {
    	engine->window.Draw((*iPlayerInfo).second);
    }
}
